package com.wyp.didishige.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.wyp.didishige.MyApplication;

/**
 * Fragmenet 基类
 *
 * @author smile
 * @ClassName: FragmentBase
 * @Description: TODO
 * @date 2014-5-22 下午2:43:50
 */
public abstract class FragmentBase extends Fragment {

    protected View contentView;

    public LayoutInflater mInflater;

    private Handler handler = new Handler();
    protected int mScreenWidth;
    protected int mScreenHeight;

    public void runOnWorkThread(Runnable action) {
        new Thread(action).start();
    }

    public void runOnUiThread(Runnable action) {
        handler.post(action);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
        mApplication = MyApplication.getInstance();
        mInflater = LayoutInflater.from(getActivity());
        DisplayMetrics metric = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
        mScreenWidth = metric.widthPixels;
        mScreenHeight = metric.heightPixels;
    }


    public FragmentBase() {

    }


    public View findViewById(int paramInt) {
        return getView().findViewById(paramInt);
    }

    public MyApplication mApplication;

    Toast mToast;

    public void ShowToast(final String text) {
        if (!TextUtils.isEmpty(text)) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    if (mToast == null) {
                        mToast = Toast.makeText(getActivity(), text,
                                Toast.LENGTH_LONG);
                    } else {
                        mToast.setText(text);
                    }
                    mToast.show();
                }
            });

        }
    }

    /**
     * 动画启动页面 startAnimActivity
     *
     * @throws
     */
    public void startAnimActivity(Intent intent) {
        this.startActivity(intent);
    }
    protected void init(){
        initWidget();
        initWidgetState();
        initWidgetListener();
    }
    protected void initParamter(){}
    protected void initWidget(){}
    protected void initWidgetListener(){}
    protected void initWidgetState(){}
}
